<?php
$loader->requireOnce('includes/ManagerDashboard/Portlet.class.php');
class PortletPatientNumber extends Portlet {
	
	function PortletPatientNumber($name, $dateRange) {
		$this->name = $name;
		$this->dateRange = $dateRange;
		$this->_db = $GLOBALS['frame']['adodb']['db'];
	}
	
	protected function collectData() {
		$sql = "SELECT count(patient_id) total, date(started) started
				FROM ticket
				INNER JOIN person ON (person.person_id = ticket.patient_id)
				WHERE date(started) <= '$this->endDate'
				AND date(started) >= '$this->startDate'
				GROUP BY date(started)";
		$result = $this->_db->GetAll($sql);
		$i = 0;
		foreach ($result as $row){
			$color = '#3030D0';
			if ($row['total'] <= 50) {
				$color = '#FF4444';
			}
			// Remember to use INTEGER data for the chart value (string will not be rendered)
			$this->values[$i] = new OFC_Charts_Line_Value((int)($row['total']), $color);
			$label = $this->getShortDate($row['started']);
			$tip = $this->getWeekDay($row['started']);
			$this->values[$i]->set_tooltip(L10nHelper::_("Examination numbers: %s%s",L10nHelper::renderNumber($row['total']),"<br>".$tip));
			$this->xLabels[$i] = $label;	
			$i++;	
		}		
	}
	
	protected function buildChart() {
		// Create chart object and set backgound color
		$this->chart = new OFC_Chart();
		$this->chart->set_bg_colour("#FEFEFE");
		// Create chart title object and pass css param
		$title = new OFC_Elements_Title($this->name);
		$title->set_style("font-size: 13px; font-weight: bold; padding-bottom: 10px; color: #00248E");
		// Create chart object (each type is an object)
		$line_dot = new OFC_Charts_Line_Dot();
		// Set chart value
		$line_dot->set_values($this->values);
		// Set lable, style for X axis
		$x_axis = new OFC_Elements_Axis_X();
		$x_axis->set_labels_from_array($this->xLabels);
		$x_axis->labels->set_rotate('diagonal');
		$x_axis->labels->set_size(9);
		$x_axis->set_colours("#555555", "#DDDDDD");
		// Set value range, step and style for Y axis
		$y_axis = new OFC_Elements_Axis_Y();
		$y_axis->set_range(0, 250, 50);
		$y_axis->set_colours("#555555", "#DDDDDD");
		// Add all of them to chart object
		$this->chart->set_title($title);
		$this->chart->add_element($line_dot);
		$this->chart->set_x_axis($x_axis);
		$this->chart->set_y_axis($y_axis);
	}
	
}
?>